package com.cxl.mapreduce._2serialize_flowsum;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * 2.需求：统计每一个手机号耗费的总上行流量、下行流量、总流量
 * @author joyson
 * @create 2019-06-07-下午1:02
 */
public class FlowsumDriver  {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        args=new String[]{"/Users/a123/devWorkspace/bigData/hdfs/src/main/resources/input/phone_data.txt"
                        ,"/Users/a123/devWorkspace/bigData/hdfs/src/main/resources/output/serialize"};

        Configuration conf = new Configuration();
        // 1 获取job对象
        Job job = Job.getInstance(conf);

        // 2 设置jar的路径
        job.setJarByClass(FlowsumDriver.class);

        // 3 关联mapper和reducer
        job.setMapperClass(FlowCountMapper.class);
        job.setReducerClass(FlowCountReducer.class);

        // 4 设置mapper输出的key和value类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        // 5 设置最终输出的key和value类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

//		job.setPartitionerClass(ProvincePartitioner.class);
//
//		job.setNumReduceTasks(6);
//

        // 6 设置输入输出路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        // 7 提交job
        boolean result = job.waitForCompletion(true);

        System.exit(result?0 :1);
    }
}
